Imports System.Xml.Serialization

Public Class Constraint
    Inherits XEntityModelElementWithDocumentationBase

    ''' <summary>Initializes an instance of the <see cref="Association" /> class.</summary>
    ''' <param name="namespace">The <see cref="XNamespace"/> of the new element.</param>
    Public Sub New(ByVal [namespace] As XNamespace)
        MyBase.New("Constraint", [namespace].ToString())
    End Sub

    ''' <summary>Initializes an instance of the <see cref="Constraint" /> class.</summary>
    ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
    Public Sub New(ByVal other As XElement)
        MyBase.New(other)
    End Sub

    <AutoLoad()> _
    <XmlElement("Principal")> _
    Public Property Principal() As ReferentialConstraintRoleElement
        Get
            Return DirectCast(Me.Element(MyBase.Name.Namespace + "Principal"), EdmxEditor.ReferentialConstraintRoleElement)
        End Get
        Set(ByVal value As ReferentialConstraintRoleElement)
            If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "Principal")) Then
                Throw New ArgumentException("Invalid Element")
            End If
            If (Me.Principal IsNot Nothing) Then
                Me.Principal.Remove()
            End If
            Me.Add(New EdmxEditor.ReferentialConstraintRoleElement(value))
        End Set
    End Property

    <AutoLoad()> _
    <XmlElement("Dependent")> _
    Public Property Dependent() As ReferentialConstraintRoleElement
        Get
            Return DirectCast(Me.Element(MyBase.Name.Namespace + "Dependent"), EdmxEditor.ReferentialConstraintRoleElement)
        End Get
        Set(ByVal value As ReferentialConstraintRoleElement)
            If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "Dependent")) Then
                Throw New ArgumentException("Invalid Element")
            End If
            If (Me.Dependent IsNot Nothing) Then
                Me.Dependent.Remove()
            End If
            Me.Add(New EdmxEditor.ReferentialConstraintRoleElement(value))
        End Set
    End Property

End Class
